package flowdroid;
import cli.ConfigManager;
import flowdroid.scan.MethodChecker;
import flowdroid.scan.ScanPhase;
import flowdroid.taint.MyProvider;
import flowdroid.taint.TaintPhase;
import tuple.TupleManager;
import util.Constant;

import static util.Constant.getApkNameFromApkFilepath;

public class Pipeline {
    public static void pipeline(String apkFileLocation, ConfigManager configManager, String dumpDir)
            throws Exception {
        MyProvider myProvider = new MyProvider();
        TupleManager manager = new TupleManager(getApkNameFromApkFilepath(apkFileLocation), TupleManager.State.NONE, dumpDir);
        MethodChecker marker = new MethodChecker();
        System.out.println("[Start] Apk:" + apkFileLocation);

        // 1. 构造调用图, 分析应用
        System.out.println("[Phase] Analyse");
        Constant.printDateTime(System.out);
        ScanPhase.scanMethods(apkFileLocation, configManager, manager, marker);

        myProvider.loadMarkedCoreMethodsAsSource(marker);
        marker.clear();

        // 2. 数据流分析
        System.out.println("[Phase] detectDataFlow");
        Constant.printDateTime(System.out);
//        TaintPhase.taintFlow(apkFileLocation, androidJarPlatform, myProvider, manager, marker);
        TaintPhase.taintFlow(apkFileLocation, configManager, myProvider, manager);
        Constant.printDateTime(System.out);
    }
}
